﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blazing.BusinessObjects.Products;
using System.Web;

namespace Blazing.WebFacade.eCommerce
{
    public class PayPalControllerWebservices
    {
        ProductsController products = new ProductsController();

        /*Credential API Signature 
API Username brenda_1245836330_biz_api1.gmail.com 
API Password UZ3R87JZRVZJ9ML6 
Signature  AV68xoDvekVChtprJENlU53ynCpvANXVbZVF0KTxUCwPEOreUtk9PaAo
Request Date 24 Jun. 2009 20:39:01 AEST 
*/
        #region Properties
        protected string APIUsername
        {
            get { return "brenda_1245836330_biz_api1.gmail.com"; }
        }

        protected string APIPassword
        {
            get { return "UZ3R87JZRVZJ9ML6"; }
        }

        protected string APISignature
        {
            get
            {
                return "AV68xoDvekVChtprJENlU53ynCpvANXVbZVF0KTxUCwPEOreUtk9PaAo";
            }
        }

        #endregion

        protected PayPal.CustomSecurityHeaderType SecurityHeader
        {
            get
            {
                var header = new PayPal.CustomSecurityHeaderType();
                header.Credentials = new Blazing.WebFacade.eCommerce.PayPal.UserIdPasswordType
                {
                    Username = APIUsername,
                    Password = APIPassword,
                    Signature = APISignature
                };

                return header;
            }
        }

        public void ProcessOrder()
        {
            PayPal.PayPalAPIInterface client = new Blazing.WebFacade.eCommerce.PayPal.PayPalAPIInterfaceClient();

            PayPal.PayPalAPIAAInterface apiaa = new PayPal.PayPalAPIAAInterfaceClient();

            var request = new Blazing.WebFacade.eCommerce.PayPal.SetExpressCheckoutReq();
            //request.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.LocaleCode

            request.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.OrderTotal = new Blazing.WebFacade.eCommerce.PayPal.BasicAmountType
            {
                currencyID = Blazing.WebFacade.eCommerce.PayPal.CurrencyCodeType.AUD,
                Value = products.GetShoppingCart().Sum(p => p.Price).ToString()
            };
            request.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.PaymentAction = Blazing.WebFacade.eCommerce.PayPal.PaymentActionCodeType.Order;
            //request.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.ReturnURL =  "";

            var response = new Blazing.WebFacade.eCommerce.PayPal.SetExpressCheckoutRequest(SecurityHeader, request);

            var doReq = new Blazing.WebFacade.eCommerce.PayPal.DoExpressCheckoutPaymentReq
            {
                DoExpressCheckoutPaymentRequest = new Blazing.WebFacade.eCommerce.PayPal.DoExpressCheckoutPaymentRequestType
                {
                    DoExpressCheckoutPaymentRequestDetails = new Blazing.WebFacade.eCommerce.PayPal.DoExpressCheckoutPaymentRequestDetailsType
                    {
                        PaymentDetails = new Blazing.WebFacade.eCommerce.PayPal.PaymentDetailsType
                        {
                            
                        }
                    }
                }
            };
        }
    }
}
